import { NextRequest, NextResponse } from 'next/server'
import { getPostByLikeTitle } from '@/lib/index'



// 获取浏览量
export async function GET(request: NextRequest) {
  try {
    const { searchParams } = new URL(request.url)
    const q = searchParams.get('q')
    if (!q) {
      return NextResponse.json({ error: '缺少查询参数' }, { status: 400 })
    }
    const posts = await getPostByLikeTitle(q)
    return NextResponse.json({ posts })
  } catch (error) {
    console.error('获取数据失败:', error)
    return NextResponse.json({ error: '服务器错误' }, { status: 500 })
  }
}